package com.vecspace.dayu.code.template.pojo;


import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vecspace.data.model.IdEntity;
import com.vecspace.data.model.RowMapper;
import com.vecspace.dicttable.CodeItem;
import com.vecspace.dicttable.DictAll;

import javax.persistence.Table;
import javax.persistence.Column;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;


/** DAYU_CODE_TEMPLATE
 * @author wanghua
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "DAYU_CODE_TEMPLATE")
public class CodeTemplate implements IdEntity, java.io.Serializable {
	
	private static final long serialVersionUID = 166432733795949426L;
	public CodeTemplate(){

	}
	
	public CodeTemplate(Long layoutId, String filePath, String codeTemplate) {
		this.layoutId = layoutId;
		this.filePath = filePath;
		this.codeTemplate = codeTemplate;
	}
	
	
	private Long id;
	/**逻辑ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId(){
		return id;
	}
	/**逻辑ID*/
	public void setId(Long value){
		this.id = value;
	}

	private Long layoutId;
	/**页面布局ID*/
	@Column(name = "LAYOUT_ID")
	public Long getLayoutId(){
		return layoutId;
	}
	/**页面布局ID*/
	public void setLayoutId(Long value){
		this.layoutId = value;
	}
	


	private String codeType;
	/**代码语言类型，dayu-CODE-031*/
	@Column(name = "CODE_TYPE")
	public String getCodeType(){
		return codeType;
	}
	/**代码语言类型，dayu-CODE-031*/
	public void setCodeType(String value){
		this.codeType = value;
	}
	/**代码语言类型，dayu-CODE-031*/
	public static final String CODE_TYPE = "DAYU-CODE-031";
	@Transient
	public String getCodeTypeCaption(){
		return DictAll.getItemName(CODE_TYPE, codeType);
	}
	@Transient
	public List<CodeItem> getCodeTypes(){
		return DictAll.getItems(CODE_TYPE);
	}
	
	private String fileParamType;
	/**文件模板使用的参数类型，dayu-CODE-033， table(根据表信息生成页面),form(根据表单信息生成页面),main(生成主页面)*/
	@Column(name = "FILE_PARAM_TYPE")
	public String getFileParamType(){
		return fileParamType;
	}
	@Transient
	public String getFileParamTypeCaption(){
		return DictAll.getItemName(FILE_PARAM_TYPE, fileParamType);
	}
	/**文件模板使用的参数类型，dayu-CODE-033， table(根据表信息生成页面),form(根据表单信息生成页面),main(生成主页面)*/
	public void setFileParamType(String value){
		this.fileParamType = value;
	}
	/**文件模板使用的参数类型，dayu-CODE-033， table(根据表信息生成页面),form(根据表单信息生成页面),main(生成主页面)*/
	public static final String FILE_PARAM_TYPE = "DAYU-CODE-033";
	@Transient
	public List<CodeItem> getFileParamTypes(){
		return DictAll.getItems(FILE_PARAM_TYPE);
	}
	
	private String summary;
	/**文件描述*/
	@Column(name = "SUMMARY_")
	public String getSummary(){
		return summary;
	}
	/**文件描述*/
	public void setSummary(String value){
		this.summary = value;
	}

	private String filePath;
	/**文件路径*/
	@Column(name = "FILE_PATH")
	public String getFilePath(){
		return filePath;
	}
	/**文件路径*/
	public void setFilePath(String value){
		this.filePath = value;
	}

	private String codeTemplate;
	/**代码模板*/
	@Column(name = "CODE_TEMPLATE")
	public String getCodeTemplateText(){
		return codeTemplate;
	}
	/**代码模板*/
	public void setCodeTemplateText(String value){
		this.codeTemplate = value;
	}

	private Integer ordnum;
	/**顺序号*/
	@Column(name = "ORDNUM")
	public Integer getOrdnum(){
		return ordnum;
	}
	/**顺序号*/
	public void setOrdnum(Integer value){
		this.ordnum = value;
	}

	private Date createTime;
	/**记录创建时间*/
	@JsonIgnore(true)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime(){
		return createTime;
	}
	/**记录创建时间*/
	public void setCreateTime(Date value){
		this.createTime = value;
	}
	@JsonIgnore(true)
	@Transient
	public String getCreateTimeStr(){
		if(createTime == null){
			return "";
		}
		String exp = "yyyy-MM-dd";
		String timestr = new java.text.SimpleDateFormat(exp).format(createTime);
		return timestr;
	}

	private String createUser;
	/**记录创建人ID*/
	@Column(name = "CREATE_USER")
	public String getCreateUser(){
		return createUser;
	}
	/**记录创建人ID*/
	public void setCreateUser(String value){
		this.createUser = value;
	}

	
	public void parseFrom(Map<String, Object> row){
		RowMapper rowMapper = new RowMapper(row);
		this.id = rowMapper.getLong("ID");
		this.layoutId = rowMapper.getLong("LAYOUT_ID");
		this.summary = rowMapper.getString("SUMMARY_");
		this.codeType = rowMapper.getString("CODE_TYPE");
		this.fileParamType = rowMapper.getString("FILE_PARAM_TYPE");
		this.filePath = rowMapper.getString("FILE_PATH");
		this.codeTemplate = rowMapper.getString("CODE_TEMPLATE");
		this.ordnum = rowMapper.getInteger("ORDNUM");
		this.createTime = rowMapper.getDate("CREATE_TIME");
		this.createUser = rowMapper.getString("CREATE_USER");
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(id == null)return false;
		CodeTemplate other = (CodeTemplate)obj;
		return id.equals(other.id);
	}

	@Override
	public int hashCode() {
		if(id == null)return 0;
		return id.hashCode();
	}
}
